package nowcoder.course;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * @author fance
 * @date 2018/7/10 19:05
 */
public class Four {

    public int[] slide(int[] arr, int n, int w) {
        // write code here
        List<Integer> ret = maxSlidingWindowCore(arr,w);
        int[] res = new int[ret.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = ret.get(i);
        }
        return res;
    }
    public List<Integer> maxSlidingWindowCore(int[] nums, int k) {
        List<Integer> ret = new ArrayList<>();
        if (nums == null) {
            return ret;
        }
        int len = nums.length;
        if (k <= 0 || k > len) {
            return ret;
        }

        for (int i = 0; i < len - k + 1; i++) {
            ArrayList<Integer> tmp = new ArrayList<>();
            for (int j = i; j < k + i; j++) {
                tmp.add(nums[j]);
            }
            Collections.sort(tmp);
            ret.add(tmp.get(tmp.size() - 1));
        }
        return ret;
    }
}
class MinStack {
    LinkedList<Integer> s;
    LinkedList<Integer> sMin;

    public MinStack() {
        s = new LinkedList<>();
        sMin = new LinkedList<>();
    }

    public void push(int node) {
        s.push(node);
        if (sMin.isEmpty() || node <= min()) {
            sMin.push(node);
        }
    }

    public void pop() {
        int cur = s.pop();
        if (cur == min()) {
            sMin.pop();
        }
    }

    public int top() {
        return s.peek();
    }

    public int min() {
        return sMin.peek();
    }
}
